

import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gczn_hd/app/core/values/app_colors.dart';
import 'package:gczn_hd/app/core/values/app_values.dart';
import 'package:gczn_hd/app/core/values/text_styles.dart';
import 'package:get/get.dart';


class GcDateTime extends StatelessWidget{

     DateTime? currentTime;
     DateTime? maxTime;
     DateTime? minTime;

   final Function(DateTime time) call;


     GcDateTime({Key? key,
  this.currentTime,
    this.maxTime,
    this.minTime,
    required this.call
  }) : super(key: key){
       currentTime ??= DateTime(2025, 3, 17);
    // maxTime ??= DateTime.now();
  }

  late DateTime _selectTime;

  @override
  Widget build(BuildContext context) {
    _selectTime = currentTime!; //

    return Column(
      children: [
        Container(
          height: AppValues.size48.h,
          padding: const EdgeInsets.only(left: 12, right: 12),
          decoration: const BoxDecoration(
            border: Border(bottom: BorderSide(color: AppColors.gcznPrimaryBlueBg))
          ),
          child: Row(
            children: [
              GestureDetector(
                child:  Text("取消", style: textStyle,),
                onTap: (){
                  Get.back();
                },
              ),
              Expanded(
                flex: 1,
                child: Center(
                  child: Text("时间选择", style: textStyle,),
                ),
              ),
              GestureDetector(
                onTap: (){
                  call(_selectTime);
                  Get.back();
                },
                child: Text("确定", style: textStyle,),
              )
            ],
          ),
        ),
        Expanded(
          flex: 1,
          child: CupertinoDatePicker(
            mode: CupertinoDatePickerMode.dateAndTime,
            initialDateTime: currentTime,
            maximumDate: maxTime,
            minimumDate: minTime,
            use24hFormat: true,
            onDateTimeChanged: (DateTime value) {
              //TODO
              _selectTime = value;
            },
          ),
        )
      ],
    );
  }

}